package com.ruoyi.config.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.check.CheckEmptyUtil;
import com.ruoyi.config.domain.ApplicationConfig;
import com.ruoyi.config.mapper.ApplicationConfigMapper;
import com.ruoyi.config.service.IApplicationConfigService;
import com.ruoyi.config.vo.UpdatePayConfigVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 应用配置Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@Service
public class ApplicationConfigServiceImpl implements IApplicationConfigService 
{
    @Autowired
    private ApplicationConfigMapper applicationConfigMapper;

    /**
     * 查询应用配置
     * 
     * @param id 应用配置主键
     * @return 应用配置
     */
    @Override
    public ApplicationConfig selectApplicationConfigById(Long id)
    {
        return applicationConfigMapper.selectApplicationConfigById(id);
    }

    /**
     * 查询应用配置列表
     * 
     * @param applicationConfig 应用配置
     * @return 应用配置
     */
    @Override
    public List<ApplicationConfig> selectApplicationConfigList(ApplicationConfig applicationConfig)
    {
        return applicationConfigMapper.selectApplicationConfigList(applicationConfig);
    }

    /**
     * 新增应用配置
     * 
     * @param applicationConfig 应用配置
     * @return 结果
     */
    @Override
    public int insertApplicationConfig(ApplicationConfig applicationConfig)
    {
        applicationConfig.setCreateTime(DateUtils.getNowDate());
        return applicationConfigMapper.insertApplicationConfig(applicationConfig);
    }

    /**
     * 修改应用配置
     * 
     * @param applicationConfig 应用配置
     * @return 结果
     */
    @Override
    public int updateApplicationConfig(ApplicationConfig applicationConfig)
    {
        applicationConfig.setUpdateTime(DateUtils.getNowDate());
        return applicationConfigMapper.updateApplicationConfig(applicationConfig);
    }

    /**
     * 批量删除应用配置
     * 
     * @param ids 需要删除的应用配置主键
     * @return 结果
     */
    @Override
    public int deleteApplicationConfigByIds(Long[] ids)
    {
        return applicationConfigMapper.deleteApplicationConfigByIds(ids);
    }

    /**
     * 删除应用配置信息
     * 
     * @param id 应用配置主键
     * @return 结果
     */
    @Override
    public int deleteApplicationConfigById(Long id)
    {
        return applicationConfigMapper.deleteApplicationConfigById(id);
    }

    @Override
    public Integer updateAllApplicationConfig(List<UpdatePayConfigVo> payConfig) {
        if (!CheckEmptyUtil.isEmpty(payConfig)){
            for (UpdatePayConfigVo updatePayConfigVo : payConfig) {
                if ("account_appid".equals(updatePayConfigVo.getCode())){applicationConfigMapper.update(updatePayConfigVo.getCode(),updatePayConfigVo.getValue());}
                if ("account_secret".equals(updatePayConfigVo.getCode())){applicationConfigMapper.update(updatePayConfigVo.getCode(),updatePayConfigVo.getValue());}
                if ("app_appid".equals(updatePayConfigVo.getCode())){applicationConfigMapper.update(updatePayConfigVo.getCode(),updatePayConfigVo.getValue());}
                if ("app_secret".equals(updatePayConfigVo.getCode())){applicationConfigMapper.update(updatePayConfigVo.getCode(),updatePayConfigVo.getValue());}
                if ("user_download_android".equals(updatePayConfigVo.getCode())){applicationConfigMapper.update(updatePayConfigVo.getCode(),updatePayConfigVo.getValue());}
                if ("user_download_ios".equals(updatePayConfigVo.getCode())){applicationConfigMapper.update(updatePayConfigVo.getCode(),updatePayConfigVo.getValue());}
                if ("user_app_version".equals(updatePayConfigVo.getCode())){applicationConfigMapper.update(updatePayConfigVo.getCode(),updatePayConfigVo.getValue());}
                if ("technician_download_android".equals(updatePayConfigVo.getCode())){applicationConfigMapper.update(updatePayConfigVo.getCode(),updatePayConfigVo.getValue());}
                if ("technician_download_ios".equals(updatePayConfigVo.getCode())){applicationConfigMapper.update(updatePayConfigVo.getCode(),updatePayConfigVo.getValue());}
                if ("technician_app_version".equals(updatePayConfigVo.getCode())){applicationConfigMapper.update(updatePayConfigVo.getCode(),updatePayConfigVo.getValue());}
                if ("technician_app_appid".equals(updatePayConfigVo.getCode())){applicationConfigMapper.update(updatePayConfigVo.getCode(),updatePayConfigVo.getValue());}
                if ("technician_app_secret".equals(updatePayConfigVo.getCode())){applicationConfigMapper.update(updatePayConfigVo.getCode(),updatePayConfigVo.getValue());}

            }
        }
        return 1;
    }
}
